// pages/mine/mine.js
import {
  ajax,
  src,
  util
} from "../../utils/util.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navData: [{
      name: "首页", //文本
      index: 0, //是否是当前页，0不是  1是
      ico: '../images/tabbar/home-sy', //不同图标
      fn: 'gotoIndex', //对应处理函数
      width: 46,
      height: 46,
    }, {
      name: "订单",
      index: 1,
      ico: '../images/tabbar/home-dd',
      fn: 'gotoOrder',
      width: 44,
      height: 44,
    }, {
      name: "自提",
      index: 2,
      ico: '../images/tabbar/home-zt',
      fn: 'gotoSelfhelp',
      width: 44,
      height: 44,
    }, {
      name: "我的",
      index: 3,
      ico: '../images/tabbar/home-wd',
      fn: 'gotoMine',
      width: 40,
      height: 44,
    }, ],
    current: 3,
    token: "",
    numlist: "",
    userinfo:"",
    zitilist:''
  },
  getselfhelplist: function () {
    ajax('/api/OrderALLORCode/Get?requestContent=' + JSON.stringify({

      token: wx.getStorageSync("Access_token")
    }), {
        header: {
          'Accept': 'application/x-www-form-urlencoded', // 默认值
        },
        method: "get",
      }, res => {
        console.log(res)
        this.setData({
          zitilist: res.Models
        })

      })
  },
  gotoIndex: function() {
    wx.reLaunch({
      url: '/pages/index/index',
    })
  },
  gotoOrder: function() {
    wx.reLaunch({
      url: '/pages/order/order',
    })
  },
  gotoSelfhelp: function() {
    wx.reLaunch({
      url: '/pages/selfhelp/selfhelp',
    })
  },
  gotoMine: function() {
    wx.reLaunch({
      url: '/pages/mine/mine',
    })
  },

  togroupbuy: function() {
    wx.navigateTo({
      url: '/pages/groupbuy/groupbuy',
    })
  },
  tocollection: function() {
    wx.navigateTo({
      url: '/pages/collection/collection',
    })
  },
  toconcern: function() {
    wx.navigateTo({
      url: '/pages/concern/concern',
    })
  },
  toadminaddress: function() {
    wx.navigateTo({
      url: '/pages/adminaddress/adminaddress',
    })
  },
  tocoupon: function() {
    wx.navigateTo({
      url: '/pages/coupon/coupon',
    })
  },
  toaftersale: function() {
    wx.navigateTo({
      url: '/pages/aftersale/aftersale',
    })
  },
  touserinfo: function() {
    wx.navigateTo({
      url: '/pages/userinfo/userinfo',
    })
  },
  toorder: function(e) {
    var index = e.currentTarget.dataset.index;

    wx.navigateTo({
      url: '/pages/order/order?index=' + index,
    })
  },
  tocomplaintmine: function() {
    wx.navigateTo({
      url: '/pages/complaint-mine/complaint-mine',
    })
  },
  tobindphone: function() {
    wx.navigateTo({
      url: '/pages/bindphone/bindphone',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  getnum: function() {
    ajax('/api/Mydisplay/Get?requestContent=' + JSON.stringify({
      Provincet: wx.getStorageSync("address_component").province,
      Cityt: wx.getStorageSync("address_component").city,
      Districtt: wx.getStorageSync("address_component").district,
      token: this.data.token
    }), {
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "get",
    }, res => {
      // console.log(res)
      this.setData({
        numlist: res.Models
      })

    })
  },

  getpersondetails: function() {
    ajax('/api/PersonDetails/GetInfo?requestContent=' + JSON.stringify({
      token: this.data.token
    }), {
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "get",
    }, res => {
      // console.log(res)
      this.setData({
        userinfo:res.Models[0]
      })

    })
  },
  onLoad: function(options) {
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#000',
    })
    var token = wx.getStorageSync("Access_token")
    this.setData({
      token: token
    })
    this.getpersondetails()
    this.getnum()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getnum()
    this.getpersondetails()
    this.getselfhelplist()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})